package com.amigo.online.provider.compare.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import com.amigo.online.provider.common.entity.MusicMysqlInfo;
import com.amigo.online.provider.common.entity.MusicSolrInfo;
import com.amigo.online.provider.common.entity.UserMongoInfo;


@Mapper
@Component
public interface MusicComparisonMapper {

    @Select("select id from music_tbl order by id  desc limit 1")
    Integer getMaxId();

    @Select("select id from music_tbl where id >= ${startId} and id <= #{endId}")
    List<UserMongoInfo> listfindByStartIdAndEndIdForMongo(@Param("startId") int startId, @Param("endId") int endId);

    @Select("select id from music_tbl where id >= ${startId} and id <= #{endId}")
    List<MusicSolrInfo> listfindByStartIdAndEndIdForSolr(@Param("startId") int startId, @Param("endId") int endId);

    @Select("SELECT t1.id FROM music_tbl t1"
            + " JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM music_tbl)-(SELECT MIN(id) FROM music_tbl))+(SELECT MIN(id) FROM music_tbl)) AS id) AS t2"
            + " WHERE t1.id >= t2.id ORDER BY t1.id LIMIT #{number}")
    List<Long> getRandomMusicId(@Param("number") int number);

    @Select("SELECT t1.id FROM music_tbl t1"
            + " JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM music_tbl)-(SELECT MIN(id) FROM music_tbl))+(SELECT MIN(id) FROM music_tbl)) AS id) AS t2"
            + " WHERE t1.id >= t2.id ORDER BY t1.id LIMIT #{number}")
    List<MusicMysqlInfo> listVideoInfoWithNumber(@Param("number") int randomComparsionNumber);
}
